﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.NetworkInformation;
using DBMgr; 

namespace XmlAppliction.PublicClass
{

    
                //  if(!Globes.M_ValidateIP("业务信息显示",Globes.GetLocalIP()))
                //{
                //    MessageBox.Show("对不起，你当前运行的位置不在许可范围内", "提示");
                //    return;
                //}
    public class CheckUser
    {
       public static string GetLocalIP()
        {
            NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
            foreach (NetworkInterface adapter in adapters)
            {

                IPInterfaceProperties adapterProperties = adapter.GetIPProperties();
                foreach (IPAddressInformation any in adapterProperties.UnicastAddresses)
                {
                    return any.Address.ToString();
                }
            }
            return "";
        }

        public static bool M_ValidateIP(string SoftName, string IP)
        {
            try
            {
                string sql = string.Format("select IPQS,IPJS from tb_cfg_dlyz where RJMC='{0}'",SoftName);
                System.Data.DataSet ds = new System.Data.DataSet();
                ds=DbHelperOra.Query(sql);
                long iplong = System.Net.IPAddress.Parse(IP).Address;
                foreach (System.Data.DataRow dr in ds.Tables[0].Rows)
                {
                    long ipqs = System.Net.IPAddress.Parse(dr[0].ToString()).Address;
                    long ipjs = System.Net.IPAddress.Parse(dr[1].ToString()).Address;
                    if (iplong >= ipqs && iplong<=ipjs)
                    {
                        return true;
                    }
                }
                return false;
            }
            catch
            {
                return false;
            }
        }
 
    }
}
